
with open('data/problem018.txt') as file:
    triangle = [map(int, line.split()) for line in file.readlines()]

bottom = len(triangle) - 1

def search(position, depth):
    value = triangle[depth][position]
    if depth == bottom:
        return value
    else:
        value1 = search(position, depth+1)
        value2 = search(position+1, depth+1) 
        return max(value1, value2) + value
        
print search(0, 0)
